﻿@using RooHui.Infrastructure.Entities.Entity;
@using RooHui.Tool;
@{
    ViewBag.Title = "融汇贷管理后台";
    Layout = "../Shared/_MainBase.cshtml";
    List<Module> menuList = ViewBag.moduleList as List<Module>;
    List<Module> firstMenu = menuList.FindAll(c => c.ParentID == 0);
    ViewBag.firstMenu = firstMenu.ToJson();
    ViewBag.menuJson = menuList.ToJson();
}
@section head{
<style type="text/css">
 #pageloading{position:absolute; left:0px; top:0px; background:white url('loading.gif') no-repeat center; width:100%; height:100%;z-index:99999;}
</style>
}
 
<div id="pageloading">
</div>
<div id="topmenu" class="l-topmenu">
    <div class="l-topmenu-logo">
        融汇贷管理后台
    </div>
    <div class="l-topmenu-welcome">
        <a href="#" class="l-link2">快捷菜单</a> <span class="space">|</span> <a href="#"
            class="l-link2" target="_blank">个人信息</a><span class="space">|</span> <a href="#"
                class="l-link2" target="_blank">密码修改</a> <span class="space">|</span> <a href="/account/logout"
                    class="l-link2">退出</a>
    </div>
</div>
<div id="layout1" style="width: 99.2%; margin: 0 auto; margin-top: 4px;background:#EAEEF5">
    <div position="left" title="主要菜单" id="menu">
        @{
            if (menuList != null && menuList.Count > 0)
            {
                foreach (var item in menuList)
                {
                    if (item.ParentID == 0)
                    {
            <div title="@item.Name" class="l-scroll">
                <ul id="tree@(item.ID)" class="ztree">
                </ul>
            </div>
                    }
                }
            }
        }
         
    </div>
    <div position="center" id="framecenter">
        <div tabid="home" title="欢迎回来">
            @RenderBody()
        </div>
    </div>
</div>
<div style="height: 32px; line-height: 32px; text-align: center;background:#EAEEF5">
    重庆xxx科技有限责任公司 版权所有 &copy; Copyright 2013 渝ICP备 xxxxxxx
</div>
<div style="display: none">
</div>
<script type="text/javascript">
    var tab = null;
    var menu = null;
    //var tree = null;
    $(function () {

        //布局
        $("#layout1").ligerLayout({
            leftWidth: 190,
            height: '100%',
            heightDiff: -34,
            space: 4,
            onHeightChanged: f_heightChanged
        });

        var height = $(".l-layout-center").height();

        //Tab
        $("#framecenter").ligerTab({ height: height});

//             $("#framecenter").ligerTab({ height: height, showSwitch: true,
//            ShowSwitchInTab: true });

        //面板
        $("#menu").ligerAccordion({ height: height - 24, speed: null });

        $(".l-link").hover(function () {
            $(this).addClass("l-link-over");
        }, function () {
            $(this).removeClass("l-link-over");
        });
        initMenu();
         

        tab = $("#framecenter").ligerGetTabManager();
        menu = $("#menu").ligerGetAccordionManager();
        //tree = $("#tree1").ligerGetTreeManager();
        $("#pageloading").hide();

    });

    function initMenu() {
    var menuJson=@Html.Raw(ViewBag.menuJson);
    var firstMenu=@Html.Raw(ViewBag.firstMenu);
        $.each(firstMenu,function(i,first){
        var zNodes=new Array();
         $.each(menuJson,function(j,item){
            if(item.ParentID==first.ID)
            {
                zNodes.push(item);
                $.each(menuJson,function(k,third){
                    if(item.ID==third.ParentID)
                    {
                       zNodes.push(third)
                    }
                });
                }
 
         });
         //树
        $("#tree"+first.ID).ligerTree({
            data: zNodes,
            checkbox: false,
            slide: false,
            nodeWidth: 120, 
            idFieldName :'ID',
            parentIDFieldName :'ParentID',
            textFieldName:'Name',
            iconFieldName:'Icon',
            btnClickToToggleOnly:false,
            attribute: ['ID', 'Url'],
            onClick: function (node) {
                if (!node.data.Url) return;
                var tabid = $(node.target).attr("tabid");
                if (!tabid) {
                    tabid = new Date().getTime();
                    $(node.target).attr("tabid", tabid)
                }
                f_addTab(tabid, node.data.Name, node.data.Url);
            }
        }); 
        });
    }

    

    function f_heightChanged(options) {
        if (tab)
            tab.addHeight(options.diff);
        if (menu && options.middleHeight - 24 > 0)
            menu.setHeight(options.middleHeight - 24);
    }
    function f_addTab(tabid, text, url) {
        tab.addTabItem({ tabid: tabid, text: text, url: url });
    }
</script>
